﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace RN.ERP.Web
{
    public partial class Error : System.Web.UI.Page
    {
        public string PageTitle
        {
            get
            {
                return ConfigurationManager.AppSettings["sysTitle"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                myStyleSheet.Attributes.Add("href", ConfigurationManager.AppSettings["AppStyle"] + "css/style.css");
                string errorCode = Request.QueryString["c"];
                if (!string.IsNullOrEmpty(errorCode))
                {
                    List<ApplicationErrorEntity> errors = Application[ApplicationConstant.APPLICATION_ERRORS] as List<ApplicationErrorEntity>;
                    ApplicationErrorEntity error = errors.SingleOrDefault(err => err.Code.ToLower() == errorCode.ToLower());
                    if (error != null)
                    {
                        lblTitle.Text = error.Title;
                        lblContext.Text = error.Text;
                        if (error.IsReturnToIndex)
                        {
                            lbQuit.Visible = true;
                        }
                        else
                        {
                            lbQuit.Visible = false;
                        }
                    }
                }
            }
        }

        protected void lbQuit_Click(object sender, EventArgs e)
        {
            UtilitiesTool.ClearSessionUserInfo();
            Response.Redirect("~/login.aspx");
        }
    }
}
